
import React from 'react'
import qs from 'qs'
import { useLocation, useParams } from 'react-router-dom';


export default function News() {
  const location = useLocation()
  console.log(location);
  //获取location.seach属性里的user数据
  const { user } = qs.parse(location.search.split("?")[1])
  //获取location.state属性数据
  const newList = location.state
  //使用useParams传参
  console.log(useParams());
  const { id } = useParams()

  return (
    <div>
      <h1>News</h1>
      <p>用户名时{user} 编号是:{id}</p>
      {
        newList.map(item => {
          return <li key={item.id}>{item.name}</li>
        })
      }
    </div>
  )
}
